import Axios from 'axios';
import env from '../../../src/config/env';
import qs from 'qs';

const listApi = `${env.oauthHost}/api/runtime/query/list`;

const detailApi = `${env.oauthHost}/api/runtime/form/load`;

const saveApi = `${env.oauthHost}/api/runtime/form/save`;

const updateTombLocationPricesApi = `${env.oauthHost}/api/muw/startUpdateExpensesWorkflow`;

const logoutProjectApi = `${env.oauthHost}/api/bizservice/method/service_test`;

const skipQueryListApi = `${env.oauthHost}/api/runtime/query/listSkipQueryList`;
// 获取墓位统计数量
const getTombLocationCountApi = `${env.oauthHost}/api/muw/getByCondition`;

const updateGbDateApi = `${env.oauthHost}/api/byg/updateGbDate`;

const updateHhDateApi = `${env.oauthHost}/api/byg/updateHhDate`;

const getDepartmentTreeApi = `${env.oauthHost}/api/runtime/organization/department/tree`;

interface QueryParams {
  filters: Array<any>;
  mobile: Boolean;
  page: Number;
  queryCode: String;
  schemaCode: String;
  size: Number;
  queryVersion: Number;
  queryCondition: Array<any>;
  showTotal: Boolean;
}

interface DetailItems {
  sheetCode: String;
  objectId: String;
  schemaCode: String;
  isWorkFlow: Boolean;
  _viewCode: String;
  return: Number;
  relevanceInfo: any;
  isMobile: Boolean;
}

interface ListData {
  content: Array<any>;
  totalElements: Number | String;
  totalPages: Number | String;
}

interface ListResponse {
  data: ListData;
  errcode: Number;
  errmsg: String;
  traceId: Boolean;
}

interface SkipQueryParams {
  queryCode: String;
  schemaCode: String;
  options: {
    customDisplayColumns: Array<String>;
  };
  orderByFields: Array<String>;
  orderType: Number;
  page: Number;
  size: Number;
  filters: Array<any>;
  condition: String;
}

export default {
  getList(params: QueryParams): Promise<ListResponse> {
    return Axios.post(`${listApi}`, params);
  },

  getDetail(params: any): Promise<any> {
    return Axios.get(`${detailApi}`, {
      params,
    });
  },

  // 获取字典类型数据
  skipQueryList(params: SkipQueryParams): Promise<ListResponse> {
    return Axios.post(`${skipQueryListApi}`, params);
  },

  save(params: any): Promise<any> {
    return Axios.post(`${saveApi}`, params);
  },
  // 更新墓地价格
  updateTombLocationPrices(params: any): Promise<any> {
    return Axios.post(`${updateTombLocationPricesApi}`, params);
  },
  // 注销项目
  logoutProject(params: any): Promise<any> {
    return Axios.post(`${logoutProjectApi}`, params);
  },

  // 获取墓位统计数量
  getTombLocationCount(params: any): Promise<any> {
    return Axios.get(`${getTombLocationCountApi}`, { params });
  },

  // 更新告别时间
  updateGbDate(params: any): Promise<any> {
    return Axios.get(`${updateGbDateApi}`, { params });
  },

  // 更新火化时间
  updateHhDate(params: any): Promise<any> {
    return Axios.get(`${updateHhDateApi}`, { params });
  },

  // 获取部门树
  getDepartmentTree(params: any): Promise<any> {
    return Axios.get(`${getDepartmentTreeApi}`, { params });
  },
};
